package MemberService

import (
	"context"
	"gdshop-font-api-go/app/request/MemberReq"
	"gdshop-font-api-go/app/response/MemberResp"
	"gdshop-font-api-go/app/service/CouponService"
	"gdshop-font-api-go/app/service/MemberBaseService"
	"gdshop-font-api-go/app/service/OrderService"
	"gdshop-font-api-go/library/response"
)

func Index(ctx context.Context, parames *MemberReq.Index) *response.JsonResponse {
	memberId := int(parames.MemberId)
	memberModel, err := MemberBaseService.GetMemberModel(ctx, memberId)
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	resultData := MemberResp.Index{
		IntegralCoin: memberModel.IntegralCoin,
		MoneyCoin:    memberModel.MoneyCoin,
		Nickname:     memberModel.Nickname,
		Avatar:       memberModel.Avatar,
	}
	resultData.OrderNum = []int{
		OrderService.GetOrderNumByMemberIdAndStatus(ctx, memberId, []int{1}),    // 待付款
		OrderService.GetOrderNumByMemberIdAndStatus(ctx, memberId, []int{2, 3}), // 待发货
		OrderService.GetOrderNumByMemberIdAndStatus(ctx, memberId, []int{4}),    // 待收货
		OrderService.GetOrderNumByMemberIdAndStatus(ctx, memberId, []int{5}),    // 待评价
		OrderService.GetOrderAftersaleNumByMemberId(ctx, memberId),              // 售后数量
	}

	resultData.Coupon = CouponService.GetMyCouponNum(ctx, memberId)

	return response.SuccessByRequestMessageData(nil, "成功", resultData)
}
